package com.ch05;

public class ShortCircuit {
	public static void main(String[] args) {
		// Boolean b1 = 4 == 2 && 1 < 4;
		Boolean b1 = operandEval(1, 4 == 2) && operandEval(2, 1 < 4);
		System.out.println();
		System.out.println("Value of b1: " + b1);
		// boolean b2 = !b1 || 2.5 > 8;
		boolean b2 = !operandEval(1, b1) || operandEval(2, 2.5 > 8);
		System.out.println();
		System.out.println("Value of b2: " + b2);
		// Boolean b3 = !(b1 && b2);
		Boolean b3 = !(operandEval(1, b1) && operandEval(2, b2));
		System.out.println();
		System.out.println("Value of b3: " + b3);
		// boolean b4 = b1 || !b3 && b2;
		boolean b4 = operandEval(1, b1) || !operandEval(2, b3)
				&& operandEval(3, b2);
		System.out.println();
		System.out.println("Value of b4: " + b4);
		// boolean b5 = b1 | !b3 & b2; // Using boolean logical operators
		boolean b5 = operandEval(1, b1) | !operandEval(2, b3)
				& operandEval(3, b2);
		System.out.println();
		System.out.println("Value of b5: " + b5);
	}

	static boolean operandEval(int opNum, boolean operand) { // (1)
		System.out.print(opNum);
		return operand;
	}
}
